import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import api from "./plugins/api";
import element from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import "@/assets/common.less";
import "@/assets/style.css";
import Table from "@/components/Table.vue";
import "default-passive-events";
import qs from "qs";
import format from "@/plugins/format";

Vue.config.productionTip = false;
Vue.prototype.$api = api;
Vue.prototype.$qs = qs;
Vue.prototype.$format = format;

(async function() {
  let { data } = await api.get("/config.json");
  api.defaults.baseURL = data.baseURL;
})();

Vue.use(element, { size: "small" });

Vue.component("Table", Table);

Vue.prototype.$formBlur = (label, value, Exp) => {
  let reg = new RegExp(Exp);
  if (!reg.test(value)) {
    element.Message.error(label);
    return false;
  }
};

Vue.prototype.$headers = { Authorization: "Bearer " + localStorage.getItem("Token") };

router.beforeEach((to, from, next) => {
  let { title } = to.meta;
  if (title) document.title = `${title} - 多艺管理后台`;
  next();
});

new Vue({
  router,
  store,
  render: h => h(App),
}).$mount("#app");
